
import pygame

class HPBar():
    
    def __init__(self, loc):
        self.loc = loc
        if(loc == 0):
            self.mainGraphic = pygame.image.load("../images/healthBars/hpbars/HealthBarPlayers.png").convert()
        else:
            self.mainGraphic = pygame.image.load("../images/healthBars/hpbars/HealthBarOpponent.png").convert()
        self.greenHealthGraphic = pygame.image.load("../images/healthBars/hpbars/greenhealth.png").convert()
        self.yellowHealthGraphic = pygame.image.load("../images/healthBars/hpbars/yellowhealth.png").convert()
        self.redHealthGraphic = pygame.image.load("../images/healthBars/hpbars/redhealth.png").convert()
        
        self.mainGraphic.set_colorkey([0, 0, 0])
        
    def setNew(self, name, currentHealth, maxHealth, status):
        self.name = name
        self.cHealth = currentHealth
        self.mHealth = maxHealth
        self.status = status
        self.forceRedraw = True
        
    def updateHealth(self, newHealth):
        self.cHealth = newHealth
        self.forceRedraw = True
        
    def getDisp(self):
        if(self.forceRedraw):
            self.healthBar = pygame.Surface((1, 2))
            if(self.cHealth > self.mHealth / 2):
                self.healthBar.blit(self.greenHealthGraphic,[0, 0])
            elif(self.cHealth > self.mHealth / 4):
                self.healthBar.blit(self.yellowHealthGraphic,[0, 0])
            else:
                self.healthBar.blit(self.redHealthGraphic,[0, 0])
            self.healthBar = pygame.transform.scale(self.healthBar, [(self.cHealth * 48) // self.mHealth, 2])
            if(self.loc == 0):
                self.finalSurface = pygame.Surface(self.mainGraphic.get_size())
                self.finalSurface.blit(self.mainGraphic, [0, 0])
                self.finalSurface.blit(self.healthBar, [57, 11])
                level = "100"
                drawLocCurrent = 89
                for n in range(0, len(level)):
                    tempImage = pygame.image.load("../images/Letters/" + level[n] + ".png")
                    tempImage.set_colorkey((189, 189, 231))
                    self.finalSurface.blit(tempImage, [drawLocCurrent, 0])
                    drawLocCurrent += tempImage.get_size()[0]
                drawLocCurrent = 17
                for n in range(0, len(self.name)):
                    tempImage = pygame.image.load("../images/Letters/u" + self.name[n] + ".png")
                    tempImage.set_colorkey((189, 189, 231))
                    self.finalSurface.blit(tempImage, [drawLocCurrent, 0])
                    drawLocCurrent += tempImage.get_size()[0]
                drawLocCurrent = 91
                for n in range(0, len(str(self.mHealth))):
                    tempImage = pygame.image.load("../images/Letters/hp" + str(self.mHealth)[n] + ".png")
                    tempImage.set_colorkey((189, 189, 231))
                    self.finalSurface.blit(tempImage, [drawLocCurrent, 15])
                    drawLocCurrent += tempImage.get_size()[0] + 2
                drawLocCurrent = 75 - (len(str(self.cHealth)) -1) * 8
                for n in range(0, len(str(self.cHealth))):
                    tempImage = pygame.image.load("../images/Letters/hp" + str(self.cHealth)[n] + ".png")
                    tempImage.set_colorkey((189, 189, 231))
                    self.finalSurface.blit(tempImage, [drawLocCurrent, 15])
                    drawLocCurrent += tempImage.get_size()[0] + 2
                return self.finalSurface
            elif(self.loc == 1):
                self.finalSurface = pygame.Surface(self.mainGraphic.get_size())
                self.finalSurface.blit(self.mainGraphic, [0, 0])
                self.finalSurface.blit(self.healthBar, [47, 14])
                level = "100"
                drawLocCurrent = 95
                for n in range(0, len(level)):
                    tempImage = pygame.image.load("../images/Letters/" + level[n] + ".png")
                    tempImage.set_colorkey((189, 189, 231))
                    self.finalSurface.blit(tempImage, [drawLocCurrent, 3])
                    drawLocCurrent += tempImage.get_size()[0]
                drawLocCurrent = 23
                for n in range(0, len(self.name)):
                    tempImage = pygame.image.load("../images/Letters/u" + self.name[n] + ".png")
                    tempImage.set_colorkey((189, 189, 231))
                    self.finalSurface.blit(tempImage, [drawLocCurrent, 3])
                    drawLocCurrent += tempImage.get_size()[0]
                return self.finalSurface
        else:
            return self.finalSurface
        
        

















